package cn.com.cennavi.java;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

public class ReadRedis {

	static String FileName = "D:\\data\\t_speed_pattern.txt";
//	static String FileName="/APP1/redis_write_20170707/t_speed_pattern.txt";
	static String filePrefix = "congestion_speed_pattern";

	/**
	 * 
	 * @Description
	 * @author buf
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		JedisCluster jedis = getJedis();
		long i=0;
		BufferedReader br = new BufferedReader(new FileReader(new File(FileName)));
		String line = br.readLine();
		while ((line = br.readLine()) != null) {
//			System.out.println(i++);
			if(i++%1000==0){
				System.out.println(i);
			}
			// WEEKDAY TIME RS_ID RS_KIND TRAVEL_TIME DEGREE RS_LENGTH SPEED
			String[] arr = line.split("\t");
			String WEEKDAY = arr[0];
			String time = arr[1];
//			String rs_id = arr[2];
//			String rs_kind = arr[3];
//			String travel_time = arr[4];
//			String degree = arr[5];
//			String rs_length = arr[6];
//			String speed = arr[7];

			//
			String key = filePrefix + "_" + WEEKDAY + "_" + time;
			System.out.println("key:  "+key);
			Iterator<String> iter1 = jedis.hkeys(key).iterator();
			while (iter1.hasNext()) {
				String key2 = iter1.next();
				List<String> ss=jedis.hmget(key, key2);
				
				for(String sss:ss){
					System.out.println(key + ":" + sss);
				}
			}
			System.out.println("asdasd");
		}
		jedis.close();
	}

	public static JedisCluster getJedis() {
		Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
		// Jedis Cluster will attempt to discover cluster nodes automatically
		jedisClusterNodes.add(new HostAndPort("172.20.10.142", 9001));
		JedisCluster jedis = new JedisCluster(jedisClusterNodes);
		return jedis;
	}
}
